21 #define D(x) cout << #x " is " << x << endl
24 dp[i][j] = Verdadero si puedo repartir los primeros i carros en orden tal que en el port haya j centÃmetros usados.
25 (El Starboard tendrÃa entonces sum[i] - j unidades usadas)
28 int choice
[205][10005], w
[205], sum
[205];
34 bool print_stupid_empty_line
= false;
37 if (print_stupid_empty_line
) cout
<< endl
;
38 print_stupid_empty_line
= true;
46 for (int x
; cin
>> x
&& x
; ){
49 sum
[n
] = sum
[n
-1] + w
[n
];
57 memset(dp
, 0, sizeof dp
);
58 memset(choice
, -1, sizeof choice
);
61 for (int i
=0; i
<n
; ++i
){
62 for (int j
=0; j
<=length
; ++j
){
64 if ((j
+ w
[i
+1]) <= length
){
65 dp
[i
+1][j
+ w
[i
+1]] = true;
66 choice
[i
+1][j
+ w
[i
+1]] = 1;
67 ans
= make_pair(i
+1, j
+ w
[i
+1]);
70 if ((sum
[i
] - j
+ w
[i
+1]) <= length
){
73 ans
= make_pair(i
+1, j
);
79 cout
<< ans
.first
<< endl
;
81 for (int i
=ans
.first
, j
=ans
.second
; i
>0 && choice
[i
][j
] != -1; --i
){
82 output
= (choice
[i
][j
] ? "port\n" : "starboard\n" ) + output
;
83 if (choice
[i
][j
]) j
-= w
[i
];